package com.autumn.word.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.xwpf.usermodel.XWPFDocument;

import com.autumn.util.ExceptionUtils;
import com.autumn.word.WorkEvaluate;
import com.autumn.word.WorkWithOptional;
import com.autumn.word.pdf.PdfConverter;

/**
 * Word 解析实现
 * 
 * @author 老码农 2019-04-24 01:17:41
 */
public class WorkEvaluateImpl implements WorkEvaluate {

	private PdfConverter pdfConverter;

	/**
	 * 
	 * @param pdfConverter
	 */
	public WorkEvaluateImpl(PdfConverter pdfConverter) {
		this.pdfConverter = pdfConverter;
	}

	@Override
	public WorkWithOptional with(File sourceFile) throws FileNotFoundException {
		ExceptionUtils.checkNotNull(sourceFile, "sourceFile");
		return new WorkWithOptionalImpl(this.pdfConverter, new FileInputStream(sourceFile), null, true);
	}

	@Override
	public WorkWithOptional with(String sourceFilePath) throws FileNotFoundException {
		ExceptionUtils.checkNotNullOrBlank(sourceFilePath, "sourceFilePath");
		return new WorkWithOptionalImpl(this.pdfConverter, new FileInputStream(sourceFilePath), null, true);
	}

	@Override
	public WorkWithOptional with(InputStream sourceFilePath) {
		return this.with(sourceFilePath, true);
	}

	@Override
	public WorkWithOptional with(XWPFDocument sourceDocument) throws IOException {
		ExceptionUtils.checkNotNull(sourceDocument, "sourceDocument");
		return new WorkWithOptionalImpl(this.pdfConverter, null, sourceDocument, true);
	}

	@Override
	public WorkWithOptional with(InputStream sourceInputStream, boolean closeStream) {
		ExceptionUtils.checkNotNull(sourceInputStream, "sourceInputStream");
		return new WorkWithOptionalImpl(this.pdfConverter, sourceInputStream, null, closeStream);
	}

}
